package com.aiyige.page.publish.guarantee.util;

import com.aiyige.model.moment.entity.Guarantee;
import com.aiyige.page.publish.guarantee.model.GuaranteeItem;
import com.aiyige.utils.ListUtil;
import com.aiyige.utils.StringUtils;

import java.util.Iterator;
import java.util.List;

public class GuaranteeUtil {

    public static String joinGuaranteeTitle(List<GuaranteeItem> list, String delimiter) {
        if (ListUtil.isEmpty(list)) return "";
        delimiter = delimiter == null ? "" : delimiter;
        StringBuilder stringBuilder = new StringBuilder();
        Iterator<GuaranteeItem> iterator = list.iterator();
        GuaranteeItem guaranteeItem = iterator.next();
        stringBuilder.append(guaranteeItem.getTitle());
        while (iterator.hasNext()) {
            stringBuilder.append(delimiter);
            stringBuilder.append(iterator.next().getTitle());
        }
        return stringBuilder.toString();
    }

    public static void resumeSelect(List<GuaranteeItem> list, List<GuaranteeItem> selectList) {
        if (ListUtil.isEmpty(list) || ListUtil.isEmpty(selectList)) return;
        outerLoop:
        for (GuaranteeItem selectItem : selectList) {
            for (GuaranteeItem item : list) {
                if (StringUtils.safeEquals(selectItem.getId(), item.getId())) {
                    item.setSelected(true);
                    continue outerLoop;
                }
            }
        }
    }
}
